<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{$shop['companyname']}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    {php echo register_jssdk(false);}
    <script src="{MODULE_URL}template/resources/js/jquery-2.1.1.min.js"></script>
    <link href="{MODULE_URL}template/resources/js/bootstrap.min.css" rel="stylesheet">
    <script src="{MODULE_URL}template/resources/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="{MODULE_URL}template/resources/layui/css/layui.css" media="all">
    <script src="{MODULE_URL}template/resources/layui/layui.js"></script>
    <script src="{MODULE_URL}template/resources/js/swiper.min.js"></script>
    <link href="{MODULE_URL}template/resources/js/swiper.min.css" rel="stylesheet">
    <script src="{MODULE_URL}template/resources/js/webcommon.js"></script>
    <script src="{MODULE_URL}template/resources/js/fastclick.min.js"></script>
    <style>
        html,body{overflow:hidden;font-size:14px;}
        body{ margin:0; background:#FFF; padding: 50px 0 0 0;}
        *{
            -webkit-overflow-scrolling: touch;
        }
        .header{height:50px; line-height:50px;text-align:center;color:#FFF;background: #5FB878; position:absolute; z-index: 2; top:0;left: 0;right:0;}
        .mainbody{width: 100%;height: 100%;overflow-y: scroll; padding:0 0 0 0;}
    </style>
    <script language="javascript">
        $(function() {
            FastClick.attach(document.body);
        });
    </script>
</head>
<body>
{if $operation=="display"}
<style>
    body a:hover,body a:active,body a:visited{text-decoration:none;}
    .pcatelist,.pcatelist li{ list-style: none;}
    .pcatelist{ background: #EEE; height: 100%; overflow-y: scroll;}
    .pcatelist li{ border-bottom:1px solid #FFF; padding: 10px; position: relative}
    .pcatelist li .showallnum{position: absolute; top: 2px;right: 2px;}
    .pcatelist li.isselect{ background: #FFF;}
    .goodlist,.goodlist li{ list-style: none;}
    .goodlist{margin:10px; overflow-y:scroll;}
    .goodlist li{ clear: both;border-bottom:1px solid #EEE;margin-bottom: 10px;}
    .goodlist li .img{width:68px; float: left;margin-right: 5px;}
    .goodlist li .img img{height:68px;width:68px;border-radius:4px;}
    .goodlist li .info {margin-left: 75px;}
    .goodlist li .info h3{ font-size: 14px; font-weight: bolder; margin-bottom: 5px;}
    .goodlist li .info .other{color: #666; margin-bottom: 5px; font-size: 12px;}
    .gprice{color: #F60;}
    .goodlist li .info a{font-size:14px; line-height:18px; border: 1px solid #2395FF;width:20px;height:20px; display:inline-block; border-radius: 100%;text-align: center; font-weight: bolder}
    .goodlist li .info a.reduce{ background: #FFF;color: #000;}
    .goodlist li .info a.reduce:active{background: #2395FF;color: #FFF;}
    .goodlist li .info a.add{ background:#2395FF;color: #FFF;}
    .goodlist li .info a.add:active{background:#FFF;color: #000;}
    .goodlist li .info input{ background: none; border: none; width:30px; text-align: center}
    footer{height:50px; line-height:50px;text-align:center;color:#FFF;background:rgba(0,0,0,0.6); position:absolute; z-index: 10; bottom:0;left: 0;right:0;}
    footer .carticon{ width: 100%; height:50px; position: relative;}
    footer .cart{border: 4px solid #666; background: #333; text-align: center; border-radius: 100%; width: 60px; height: 60px; line-height:50px; font-size:20px; position: absolute; bottom:10px;left: 20px; color:#2395FF;}
    .totalprice{ font-size: 16px;color: #FFF; text-indent: 10px; font-weight: bolder}
    footer .showallnum{position: absolute;bottom:45px;left:55px;}

    .showbox{ background: #FFF;}
    .showbox h3{ font-size: 14px; font-weight: bolder; margin-bottom: 5px;}
    .showbox p{ margin: 5px 0;}
    .showbox .gprice{ font-family: Arial; font-size: 14px; font-weight: bolder;color: #F60;}
    .showbox a{ background:#2395FF;color: #FFF; border-radius:10px; padding: 3px 5px;}
    .shopcartbox{position: absolute;left:0;right: 0;top: 0;bottom: 0; z-index: 2;}
    .shopcartbox .masker{position: absolute;left:0;right: 0;top: 0;bottom: 0; z-index: 3; background: rgba(0,0,0,0.6);}
    .shopcartbox .shopcart{background: #FFF;position: absolute; z-index:4;bottom:50px;left:0;right: 0;}
    .shopcart_top{ background: #DDD;color: #000; padding: 10px;}

    .menulist{overflow-y: scroll}
    .menulist,.menulist li{ list-style: none;}
    .menulist li{ padding: 5px 10px; background: #FFF; border-bottom: 2px solid #EEE;display:-webkit-box;display:-webkit-flex;display:flex;-webkit-box-align:center;-webkit-align-items:center;align-items:center;height:50px;}
    .menulist li div[class^='layui-col-'] p{width:100%; font-size: 12px; color: #999}
    .menulist li a{font-size:14px; line-height:18px; border: 1px solid #2395FF;width:20px;height:20px; display:inline-block; border-radius: 100%;text-align: center; font-weight: bolder}
    .menulist li a.reduce{ background: #FFF;color: #000;}
    .menulist li a.reduce:active{background: #2395FF;color: #FFF;}
    .menulist li a.add{ background:#2395FF;color: #FFF;}
    .menulist li a.add:active{background:#FFF;color: #000;}
    .menulist li a:hover,.menulist li a:active,.menulist li a:visited{text-decoration: none;}
    .menulist li input{ background: none; border: none; width:30px; text-align: center}

    .showtaste{padding: 10px;}
    .showtaste span{ border: 1px solid #CCC; padding: 5px; display: inline-block; margin: 5px; background:#FFF; color: #333;border-radius: 4px}
    .showtaste span.isselect{ background:#01AAED;border-color:#01AAED;color: #FFF;}

</style>
<section class="header layui-row">
    <div class="layui-col-xs2"><a style="color:#FFF" href="{php echo $this->createMobileUrl('placeorder',array('op'=>'display','shopid'=>$shopid))}"><i class="fa fa-home"></i></a></div>
    <div class="layui-col-xs8">点餐</div>
    <!--<div class="layui-col-xs2"><a style="color:#FFF" href="{php echo $this->createMobileUrl('placeorder',array('op'=>'memberorderlist','shopid'=>$shopid))}"><i class="fa fa-user"></i></a></div>-->
    <div class="layui-col-xs2"></div>
</section>

<section class="mainbody layui-row">
    <div class="layui-col-xs3">
        <ul class="pcatelist">
            {loop $goodpcatelist $row}
            <li pcate="{$row['id']}" onclick="selectPcate({$row['id']})">{$row['title']}</li>
            {/loop}
        </ul>
    </div>
    <div class="layui-col-xs9">
        <ul class="goodlist">

        </ul>
    </div>
</section>
<footer class="layui-row">
    <div class="layui-col-xs3"><div class="carticon" onclick="showCart(1)"><div class="cart"><i class="fa fa-folder-close"></i></div></div></div>
    <div class="layui-col-xs6 text-left totalprice">￥0.00</div>
    <div class="layui-col-xs3" style="background:#5FB878" onclick="submitOrder()">下一步</div>
</footer>
<div class="shopcartbox" style="display: none;">
    <div class="masker" onclick="showCart(0)"></div>
    <DIV class="shopcart">
        <div class="shopcart_top">已选商品<span class="pull-right" onclick="clearOrder()">清空</span></div>
        <ul class="menulist">

        </ul>
    </DIV>
</div>

<div class="showtastebox" style="display: none;">
    <DIV class="showtaste"></DIV>
</div>
<script language="javascript">
    var orderArystr='{php echo $orderAry ? htmlspecialchars_decode($orderAry) : "[]" }';
    var orderAry=orderArystr.length>10 ? eval('('+orderArystr+')'): {};
    var isMember=parseInt("");
    $(document).ready(function(){
        $("body").height($(window).height()-50);
        var _h=$(window).height()-100;
        $(".mainbody").height(_h);
        $(".pcatelist").height(_h-20);
        $(".goodlist").height(_h);
    })
    layui.use(['layer', 'element','form'], function(){
        var layer = layui.layer
                ,element = layui.element
                ,form = layui.form;
        form.render();
        $(".pcatelist li").eq(0).click();
    })
    function showGood(id){
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('placeorder',array('op'=>'getgood'))}",{id:id},function(returnstr) {
            layer.close(index2);
            var result = eval("(" + returnstr + ")");
            if (result.success) {
                var _w=$(window).width()*0.8-10;
                var item=result.item;
                layer.open({
                    title: 0
                    ,area:_w+"px"
                    ,shade: [0.6, '#000000']
                    ,shadeClose:true
                    ,btn:0
                    ,content: '<div class="showbox"><div style="margin-bottom: 10px;"><img onerror="this.src=\'{MODULE_URL}template/resources/img/002.png\'" src="'+item.thumb+'" style="width: 100%;height: '+(_w/4*3)+'px"/></div><h3>'+item.title+'</h3><p class="help-block">'+(item.description)+'</p><p><span class="gprice">￥ '+(!isMember ? item.marketprice : item.memberprice)+'</span>  <span class="pull-right"><a href="javascript:">加入购物车</a></span></p></div>'
                    ,success: function(layero, index){
                        $(".showbox a").bind("click",function(){
                            layer.close(index);
                            addnum(id);
                        });
                    }
                    ,end:function(){
                        $(".showbox a").unbind("click");
                    }
                });
            }else{
                layer.msg(result.msg, {icon: 2, time: 2000});
                return false;
            }
        });
    }
    function selectPcate(cid){
        $(".pcatelist li[pcate='"+cid+"']").addClass("isselect").siblings().removeClass("isselect");
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('placeorder',array('op'=>'getgoodlist'))}",{cid:cid},function(returnstr) {
            layer.close(index2);
            var result = eval("(" + returnstr + ")");
            if (result.success) {
                var list = result.list;
                //--添加商品--//
                $(".goodlist").empty();
                for(var i in list){
                    var temp='<li gid="'+list[i].id+'" pcate="'+list[i].pcate+'" price="'+(!isMember ? list[i].marketprice : list[i].memberprice)+'" oprice="'+list[i].marketprice+'" mprice="'+list[i].memberprice+'"  taste="'+list[i].taste+'"><div class="img" onclick="showGood('+list[i].id+')"><img onerror="this.src=\'{MODULE_URL}template/resources/img/002.png\'" src="'+list[i].thumb+'"/></div> <div class="info">';
                    temp+='<h3>'+list[i].title+'</h3><p class="other">&nbsp</p>';
                    temp+='<p><span class="gprice">￥'+(!isMember ? list[i].marketprice : list[i].memberprice)+'</span> /'+list[i].unitname+' <span class="pull-right"><a href="javascript:reduce('+list[i].id+')" class="reduce hideobj" style="display:none">-</a><input type="text" class="gnum hideobj" value="0" readonly style="display:none"/><a href="javascript:addnum('+list[i].id+')" class="add">+</a> </span></p> </div><div>&nbsp</div> </li>';
                    $(".goodlist").append(temp);
                    if(orderAry[list[i].id]){
                        $(".goodlist li[gid='"+list[i].id+"'] .gnum").val(orderAry[list[i].id]["num"]);
                        $(".goodlist li[gid='"+list[i].id+"'] .hideobj").show();
                    }
                    countOrder();
                }
                $(".goodlist").scrollTop(0);
            }else{
                layer.msg(result.msg, {icon: 2, time: 2000});
                return false;
            }
        });
    }
    function reduce(obj){
        var num=parseInt($(".goodlist li[gid='"+obj+"'] .gnum").val())-1;
        var price=parseInt(parseFloat($(".goodlist li[gid='"+obj+"']").attr("price"))*100);
        $(".goodlist li[gid='"+obj+"'] .gnum").val(num);
        if(num<=0){
            $(".goodlist li[gid='"+obj+"'] .hideobj").hide();
            $(".menulist li[gid='"+obj+"']").remove();
        }else{
            if($(".menulist li[gid='"+obj+"']").size()>1){
                var num2=parseInt($(".menulist li[gid='"+obj+"']:eq(0) .menunum").val());
                if(num2-1<=0){
                    $(".menulist li[gid='"+obj+"']:eq(0)").remove();
                }else{
                    $(".menulist li[gid='"+obj+"']:eq(0) .menunum").val(num);
                    $(".menulist li[gid='"+obj+"']:eq(0) .menufee").text("￥"+fee2num(price*num));
                }
            }else{
                $(".menulist li[gid='"+obj+"'] .menunum").val(num);
                $(".menulist li[gid='"+obj+"'] .menufee").text("￥"+fee2num(price*num));
            }
        }
        countOrder();
    }
    function addnum(obj){
        var num=parseInt($(".goodlist li[gid='"+obj+"'] .gnum").val())+1;
        var price=$(".goodlist li[gid='"+obj+"']").attr("price");
        var pcate=$(".goodlist li[gid='"+obj+"']").attr("pcate");
        var title=$(".goodlist li[gid='"+obj+"'] h3").text();
        var taste=$(".goodlist li[gid='"+obj+"']").attr("taste");
        if(taste){
            if(arguments.length<2){
                showTaste(obj);
                return;
            }
            var tTast=arguments[1];
            if($(".menulist li[gid='"+obj+"'] .taste:contains('"+tTast+"')").map(function(){
                        if ($(this).text()==tTast)return this;
                    }).size()>0){
                var target=$(".menulist li[gid='"+obj+"'] .taste:contains('"+tTast+"')").map(function(){
                    if ($(this).text()==tTast)return this;
                }).parent().parent();
                var num2=parseInt(target.find(".menunum").val())+1;
                target.find(".menunum").val(num2);
                var price2=parseInt(parseFloat(price)*100);
                target.find(".menufee").text("￥"+fee2num(price2*num2));
            }else{
                var temp='<li class="layui-row" gid="'+obj+'" price="'+price+'" pcate="'+pcate+'" title="'+title+'"><div class="layui-col-xs6">'+title+'<p class="taste">'+tTast+'</p></div><div class="layui-col-xs3 menufee">￥'+price+'</div> <div class="layui-col-xs3 text-right"><a href="javascript:" onclick="menureduce(this)" class="reduce">-</a><input type="text" class="menunum" value="1" readonly/><a href="javascript:" class="add" onclick="menuaddnum(this)">+</a></div></li>';
                $(".menulist").append(temp);
            }
        }else{
            if($(".menulist li[gid='"+obj+"']").size()>0){
                var num2=parseInt($(".menulist li[gid='"+obj+"'] .menunum").val())+1;
                $(".menulist li[gid='"+obj+"'] .menunum").val(num2);
                var price2=parseInt(parseFloat(price)*100);
                $(".menulist li[gid='"+obj+"'] .menufee").text("￥"+fee2num(price2*num2));
            }else {
                var temp = '<li class="layui-row" gid="' + obj + '" price="' + price + '" pcate="' + pcate + '" title="' + title + '"><div class="layui-col-xs6">' + title + '</div><div class="layui-col-xs3 menufee">￥' + price + '</div> <div class="layui-col-xs3 text-right"><a href="javascript:" onclick="menureduce(this)" class="reduce">-</a><input type="text" class="menunum" value="1" readonly/><a href="javascript:" class="add" onclick="menuaddnum(this)">+</a></div></li>';
                $(".menulist").append(temp);
            }
        }
        $(".goodlist li[gid='"+obj+"'] .gnum").val(num);
        $(".goodlist li[gid='"+obj+"'] .hideobj").show();
        countOrder();
    }
    function showTaste(id){
        var _w=$(window).width()*0.8;
        $(".showtaste").empty();
        layer.open({
            title: 0
            ,type: 1
            ,area:_w+"px"
            ,shade: [0.6, '#000000']
            ,btn:["选择","关闭"]
            ,btn1:function(index, layero){
                if($(".showtaste .isselect").size()==0){
                    layer.msg("请选择商品属性", {icon: 2, time: 1500});
                    return;
                }
                var temptxt=[]
                $(".showtaste .isselect").each(function(indexs){
                    temptxt.push($(this).text());
                })
                addnum(id,temptxt.join(","));
                layer.close(index);
            }
            ,content: $(".showtastebox").show()
            ,success: function(layero, index){
                var taste=$(".goodlist li[gid='"+id+"']").attr("taste");
                console.log(taste);
                var tempAry=taste.split("|");
                for(var i in tempAry){
                    $(".showtaste").append("<span>"+tempAry[i]+"</span>");
                }
                $(".showtaste span").bind("click",function(){
                    if($(this).hasClass("isselect")){
                        $(this).removeClass("isselect");
                    }else{
                        $(this).addClass("isselect");
                    }
                });
            }
            ,end:function(){
                $(".showtastebox").hide();
                $(".showtaste span").unbind("click");
            }
        });
    }
    function showCart(obj){
        if(obj==0){
            var h=$('.shopcart').height();
            $('.shopcart').css('bottom',-h);
            $('.shopcartbox').hide();
            return;
        }
        var _w=$(window).width();
        var _h=$(window).height()*0.7;
        $(".shopcart").height(_h);
        $(".menulist").height(_h-40);
        $(".shopcart").css("bottom",-_h);
        $(".shopcartbox").show();
        $(".shopcart").css({"bottom":"50px","transition":"all 0.2s ease-out"});
    }
    function menureduce(obj){
        var target=$(obj).parent().parent();
        var gid=target.attr("gid");
        var price=parseInt(parseFloat(target.attr("price"))*100);
        var num=parseInt(target.find(".menunum").val())-1;
        if(num<=0){
            target.remove();
        }else{
            target.find(".menunum").val(num);
            var price=parseInt(parseFloat(target.attr("price"))*100);
            target.find(".menufee").text("￥"+fee2num(price*num));
        }
        if($(".goodlist li[gid='"+gid+"']").size()){
            var num2=parseInt($(".goodlist li[gid='"+gid+"'] .gnum").val())-1;
            if(num2<=0){
                $(".goodlist li[gid='"+gid+"'] .hideobj").hide();
            }
            $(".goodlist li[gid='"+gid+"'] .gnum").val(num2);
        }
        countOrder();
    }
    function menuaddnum(obj){
        var target=$(obj).parent().parent();
        var gid=target.attr("gid");
        var num=parseInt(target.find(".menunum").val())+1;
        target.find(".menunum").val(num);
        var price=parseInt(parseFloat(target.attr("price"))*100);
        target.find(".menufee").text("￥"+fee2num(price*num));
        if($(".goodlist li[gid='"+gid+"']").size()){
            var num2=parseInt($(".goodlist li[gid='"+gid+"'] .gnum").val())+1;
            $(".goodlist li[gid='"+gid+"'] .gnum").val(num2);
        }
        countOrder();
    }
    function countOrder() {
        var totalprice = 0;
        var allnum = 0;
        var pcatenum = [];
        $(".pcatelist .showallnum").remove();
        $(".menulist li").each(function(){
            var price=parseInt(parseFloat($(this).attr("price"))*100);
            var num=parseInt($(this).find(".menunum").val());
            var pcate=$(this).attr("pcate");
            var gid=$(this).attr("gid");
            totalprice+=price*num;
            allnum+=num;
            if($(".pcatelist li[pcate='"+pcate+"'] .showallnum").size()){
                var num2=parseInt($(".pcatelist li[pcate='"+pcate+"'] .showallnum").text());
                $(".pcatelist li[pcate='"+pcate+"'] .showallnum").text(num2+num);
            }else{
                $(".pcatelist li[pcate='"+pcate+"']").append('<span class="layui-badge showallnum">'+num+'</span>');
            }
        });
        $("footer .totalprice").text("￥"+(totalprice*0.01).toFixed(2));
        if (allnum) {
            if ($("footer .showallnum").size()) {
                $("footer .showallnum").text(allnum);
            } else {
                $("footer .carticon").append('<span class="layui-badge showallnum">' + allnum + '</span>');
            }
        }else{
            $("footer .showallnum").remove();
        }
    }
    function clearOrder(){
        layer.confirm('清空购物车中所有商品？', function(index){
            $(".menulist").empty();
            $(".goodlist .gnum").val("0");
            $(".goodlist .hideobj").hide();
            countOrder();
            layer.close(index);
        });
    }
    function submitOrder(){
        if($(".menulist li").size()==0){
            layer.msg("请先选择商品", {icon: 2, time:1500});
            return false;
        }
        if($(".shopcartbox").is(":hidden")){
            showCart();
            return;
        }
        var orderAry=[];
        $(".menulist li").each(function(indexnum){
            var gid=$(this).attr("gid");
            var num=$(this).find(".menunum").val();
            var title=$(this).attr("title");
            var taste=$(this).find(".taste").text();
            var tempstr=gid+"|*|"+num+"|*|"+taste+"|*|"+title;
            orderAry.push(tempstr);
        });
        var index2=layer.load(1, {shade: [0.1,'#fff'],time:4000},function(){
            location.reload();
        });
        $.post("{php echo $this->createMobileUrl('placeorder',array('op'=>'updateordergoods'))}",{orderAry:orderAry.join("|**|")},function(returnstr) {
            console.log(returnstr);
            var result = eval("(" + returnstr + ")");
            if (result.success) {
                location.href="{php echo $this->createMobileUrl('placeorder',array('op'=>'page_submit','tid'=>$tableid))}";
            }else{
                layer.close(index2);
                layer.msg(result.msg, {icon: 2, time: 2000});
                return false;
            }
        });
    }
</script>
{elseif $operation=="page_submit"}
<style>
    .top_msg{padding: 10px;text-align: center; font-size: 16px; border-bottom: 1px dashed #CCC; margin-bottom: 10px;}
    .form_info{padding: 10px;border-bottom: 1px dashed #CCC; margin-bottom: 10px;}
    .form_info .layui-row{ margin-bottom: 10px;}
    .form_info .layui-row div[class^='layui-col']:first-child h3{width:90%; line-height:34px; font-size: 20px;}
    .showpricebox{padding: 10px;text-align: center;font-size: 20px;font-family: Arial; font-weight: bolder;color: #F60;}
    .submitbtn{padding: 10px;text-align: center;}
</style>
<section class="header layui-row">
    <div class="layui-col-xs2"><a style="color:#FFF" href="{php echo $this->createMobileUrl('placeorder',array('op'=>'display'))}"><i class="fa fa-home"></i></a></div>
    <div class="layui-col-xs8">收银结账</div>
    <div class="layui-col-xs2"></div>
</section>
<div class="top_msg">欢迎使用堂食点餐</div>
<div class="form_info">
    <div class="layui-row">
        <div class="layui-col-xs4"><h3>数量</h3></div>
        <div class="layui-col-xs8">
            <input type="text" readonly class="form-control" value="{php echo $num}"/>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs4"><h3>餐台</h3></div>
        <div class="layui-col-xs8">
            <input type="hidden" id="input_tableid" value="{php echo $tableid}"/>
            <button type="button" style="line-height: 34px;height: 34px;" onclick="scranTable()" id="tablename" class="layui-btn layui-btn-normal btn-block">{if $table}{$table["title"]}{else}扫描餐台二维码{/if}</button>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs12">
            <input type="text" id="input_remark" placeholder="备注"  class="form-control"/>
        </div>
    </div>
</div>
<div class="showpricebox">
    <small>￥</small> {php echo $totalfee} 元
</div>
<div class="submitbtn">
    <button type="button" class="layui-btn layui-btn-warm layui-btn-big btn-block" id="submitbtn" {if !$table}disabled{/if} onclick="submitOrder()" >确认下单</button>
</div>
<script>
    layui.use(['layer', 'element','form'], function(){
        var layer = layui.layer
                ,element = layui.element
                ,form = layui.form;
        form.render();
    })
    function scranTable(){
        $("#submitbtn").attr("disabled",true);
        wx.scanQRCode({
            needResult: 1,
            scanType: ["qrCode"],
            success: function (res) {
                var resultcode = res.resultStr;
                var index2=layer.load(1, {shade: [0.1,'#fff']});
                $.post("{php echo $this->createMobileUrl('placeorder',array('op'=>'scantable'))}",{"code":encodeURI(resultcode)},function(returnstr) {
                    layer.close(index2);
                    var result = eval("(" + returnstr + ")");
                    if (result.success) {
                        $("#submitbtn").removeAttr("disabled");
                        var tableItem=result.item;
                        $("#input_tableid").val(tableItem["id"]);
                        $("#tablename").text(tableItem["tablename"]);
                    }else{
                        layer.msg(result.msg, {icon: 2, time: 2000});
                        return false;
                    }
                });
            }
        });
    }
    function submitOrder(){
        var tableid=parseInt($("#input_tableid").val());
        if(!tableid){
            layer.msg("请选择餐台", {icon: 2, time: 2000});
            return false;
        }
        var remark=$("#input_remark").val();
        var index2=layer.load(1, {shade: [0.3,'#000'],shadeClose:true});
        $.post("{php echo $this->createMobileUrl('placeorder',array('op'=>'submitorder'))}",{"tableid":tableid,"remark":remark},function(returnstr) {
            console.log(returnstr);
            var result = eval("(" + returnstr + ")");
            if (result.success) {
                location.href="{php echo $this->createMobileUrl('placeorder',array('op'=>'memberorderview'))}&orderid="+result.orderid;
            }else{
                layer.close(index2);
                layer.msg(result.msg, {icon: 2, time: 2000});
                return false;
            }
        });
    }

</script>
{elseif $operation=="memberorderview"}
<style>
    .flipx {-webkit-transform:scaleX(-1);  transform:scaleX(-1);  filter:FlipH;  }
    .order_info{padding:10px;border-bottom: 1px dashed #CCC; margin-bottom: 10px;}
    .order_info h3{margin-right: 5px; color: #666}
    .order_info .layui-row div[class^='layui-col']{ line-height:22px;}
    .colorred{color: #F60}
    .goodlist .layui-row{display:-webkit-box;display:-webkit-flex;display:flex;-webkit-box-align:center;-webkit-align-items:center;align-items:center;height:50px;border-bottom: 1px dashed #CCC;}
    .goodlist .layui-row:last-child{border-bottom: none;}
    .goodlist .layui-row p{font-size: 12px; color:#666;}
</style>
<section class="header layui-row">
    <div class="layui-col-xs2"><a style="color:#FFF" href="{php echo $this->createMobileUrl('placeorder',array('op'=>'display','shopid'=>$shopid))}"><i class="fa fa-home"></i></a></div>
    <div class="layui-col-xs8">订单详情</div>
    <div class="layui-col-xs2"></div>
</section>
<div class="mainbody">
    <div class="order_info">
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>订单状态：</h3></div>
            <div class="layui-col-xs9">{if $trade['ispay']}<span class='label label-success'>已支付</span>{else}<span class='label label-default'>待支付</span>{/if}</div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>下单门店：</h3></div>
            <div class="layui-col-xs9">{$ordershop}</div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>订单编号：</h3></div>
            <div class="layui-col-xs9">{$trade['out_trade_no']}</div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>开台时间：</h3></div>
            <div class="layui-col-xs9">{php echo date("Y-m-d H:i",$trade['createtime'])}</div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>餐台：</h3></div>
            <div class="layui-col-xs9">{$tablepcatename}-{$table['title']}</div>
        </div>
    </div>
    <div class="order_info">
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>商品总额：</h3></div>
            <div class="layui-col-xs9 text-right">{if $trade['ispay']}<span class='label label-success'>已支付</span>{else}<span class='label label-default'>待支付</span>{/if} ￥ <span class="colorred">{php echo sprintf('%.2f',$trade['order_fee']*0.01)}</span></div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>茶位费：</h3></div>
            <div class="layui-col-xs9 text-right">{if $trade['ispay']}<span class='label label-success'>已支付</span>{else}<span class='label label-default'>待支付</span>{/if} ￥ <span class="colorred">{php echo sprintf('%.2f',$trade['teafee']*0.01)}</span></div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>我的费用：</h3></div>
            <div class="layui-col-xs9 colorred text-right"> ￥ <span class="colorred">{php echo sprintf('%.2f',$selffee*0.01)}</span></div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>合计：</h3></div>
            <div class="layui-col-xs9 text-right"> ￥ <span class="colorred">{php echo sprintf('%.2f',($trade['teafee']+$trade['order_fee'])*0.01)}</span></div>
        </div>
        {if $trade['ispay']}
        <div class="layui-row">
            <div class="layui-col-xs3"><h3>实际支付：</h3></div>
            <div class="layui-col-xs9 text-right"> ￥ <span class="colorred">{php echo sprintf('%.2f',$trade['paid_fee']*0.01)}</span></div>
        </div>
        {/if}
    </div>
    <div class="order_info goodlist">
        {loop $ordergoods $row}
        <div class="layui-row">
            <div class="layui-col-xs6">{$row['title']}<p>{$row['taste']}</p></div>
            <div class="layui-col-xs2 text-center">{$row['num']}</div>
            <div class="layui-col-xs4 text-right">
                {if $row['openid']==$openid}
                <span class='label label-success'>我点</span>
                {/if}
                ￥ <span class="colorred">{php echo sprintf('%.2f',$row['total_fee']*0.01)}</span>
            </div>
        </div>
        {/loop}
    </div>
</div>
<script>
    $(document).ready(function(){
        var _h=$(window).height();
        $(".mainbody").height(_h-50);
    });
    layui.use(['layer', 'element','form'], function(){
        var layer = layui.layer
                ,element = layui.element
                ,form = layui.form;
        form.render();
    })
</script>
{elseif $operation=="memberorderlist"}
<style>
    .orderlist{padding: 10px;}

    .orderlist li {border-bottom: 1px solid #CCC; margin-top: 10px;}
    .orderlist li h3{font-size: 14px;font-weight: bolder;width: 100%; line-height: 20px;}
    .orderlist li .info{line-height: 20px;}
    .goodlist{padding: 10px;width: 100%;overflow-x: scroll;white-space: nowrap;overflow-y: hidden}
    .goodlist div{text-align: center; width: 60px; margin-right: 6px; display: inline-block;font-size: 10px;}
    .goodlist div img{width: 60px;height: 60px; display: block;margin-bottom: 5px;}
</style>
<section class="header layui-row">
    <div class="layui-col-xs2"><a style="color:#FFF" href="{php echo $this->createMobileUrl('placeorder',array('op'=>'display','shopid'=>$shopid))}"><i class="fa fa-home"></i></a></div>
    <div class="layui-col-xs8">订单列表</div>
    <div class="layui-col-xs2"><a style="color:#FFF" href="{php echo $this->createMobileUrl('placeorder',array('op'=>'memberorderlist','shopid'=>$shopid))}"><i class="fa fa-user"></i></a></div>
</section>
<div class="mainbody">
    <ul class="orderlist">
        {loop $orderlist $row}
        <li onclick="location.href='{php echo $this->createMobileUrl('placeorder',array('op'=>'memberorderview'))}&orderid={$row['id']}'">
            <h3>桌号:{php echo $tableAry[$row['tableid']]}<span class="pull-right">{$shopary[$row['groupid']]}</span></h3>
            <div class="info">{php echo date("Y/m/d H:i",$row['createtime'])}<span class="pull-right">￥ {php echo sprintf('%.2f',$row['paid_fee']*0.01);} {if $row['ispay']}<span class='label label-success'>已付</span>{else}<span class='label label-default'>待付</span>{/if}</span></div>
            <div class="goodlist">
                {loop $orderAry[$row['id']] $row1}
                <div>
                    <img src="{php echo tomedia($row1['thumb'])}" onerror="this.src='{MODULE_URL}template/resources/img/002.png'" />
                    {$row1['title']}
                </div>
                {/loop}
            </div>
        </li>
        {/loop}
    </ul>
    <div style="padding:10px; text-align: center"><div id="pageindex"></div></div>
</div>

<script>
    $(document).ready(function(){
        var _h=$(window).height();
        var _w=$(window).width();
        $(".mainbody").height(_h-50);
        $(".goodlist").width(_w-40);
    });
    layui.use(['layer', 'element','laypage','form'], function(){
        var layer = layui.layer
                ,element = layui.element
                ,laypage = layui.laypage
                ,form = layui.form;

        form.render();
        laypage.render({
            elem: 'pageindex'
            ,count: parseInt("{$total}")
            ,limit: parseInt("{php echo $psize}")
            ,curr: parseInt("{php echo $pindex}")
            ,jump: function(obj, first){
                var curr = obj.curr;
                var currpage=parseInt("{php echo $pindex}");
                if(curr!=currpage){
                    var page=getUrlParam('page');
                    var url=window.location.search;
                    if(page==""){
                        url+="&page="+curr
                    }else{
                        url2=url.replace("&page="+page,"");
                        url=url2+"&page="+curr;
                    }
                    location.href="./index.php"+url;
                }
            }
        });
    })
    function getUrlParam(name){
        var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
        var r =  window.location.search.substr(1).match(reg);
        var strValue = "";
        if (r!=null){
            strValue= unescape(r[2]);
        }
        return strValue;
    }
</script>
{/if}